
//
// 101125 - AH - Created.
// 110605 - AH - (Garage) Changes related to that resource name is now a 
//               SoekrateName.
// 110614 - AH - (Bybanen *) Now extends DefaultTreeCellRenderer so can be
//               used with DefaultTreeCellEditor.
//

package org.soekrat.gui.swing.resource;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.mine.Resource;

/**
 * <p>
 *   {@link TreeCellRenderer} for 
 *   {@link Mine} resources.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class ResourceTreeCellRenderer extends DefaultTreeCellRenderer 
{
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public static final DefaultTreeCellRenderer INSTANCE=
    new ResourceTreeCellRenderer();
  
  //private final ImageIcon m_icon;
  
  //private final DefaultTreeCellRenderer m_dtcrN=new DefaultTreeCellRenderer();
  
  //private final DefaultTreeCellRenderer m_dtcr=new DefaultTreeCellRenderer();
  
  // Singleton pattern dictates private constructor.
  private ResourceTreeCellRenderer() 
  {
	  //URL iconUrl=getClass().getResource(
	  //  "/org/soekrat/gui/swing/icons/miniMine2.png");
	
	  //m_icon=new ImageIcon(iconUrl);
	    
	  //m_dtcrN.setClosedIcon(m_icon);
	  //m_dtcr.setOpenIcon(m_icon);
	}

  // Specified in TreeCellRenderer.
  public Component getTreeCellRendererComponent(JTree tree, Object value,
      boolean selected, boolean expanded, boolean leaf, int row,
      boolean hasFocus) 
  {
    String text=value.toString();
    if (value instanceof Resource)
    {
      text=((Resource)value).getSoekratName().toString();
    }
    
    /*
    String text=null;
    if (value instanceof Resource)
    {
      text=((Resource)value).getSoekratName().toString();
      
      if (text==null)
      {
        return m_dtcrN.getTreeCellRendererComponent(tree, text, selected, 
          expanded, leaf, row, hasFocus);
      }
      else {
    	  return m_dtcrN.getTreeCellRendererComponent(tree, text, selected, 
    		  expanded, leaf, row, hasFocus);  
      }
    }
    
    text=(text==null) ? value.toString() : text;
    */
    
    return super.getTreeCellRendererComponent(tree, text, selected, expanded, 
      leaf, row, hasFocus);
  }
  
}
